
#include "threadpool.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "pthread.h"
#include <atomic>
std::atomic<int> g_value(0);

void taskFunc(void* arg)
{
    // int num = (int)arg;
    int num =  (int)(intptr_t)arg;
    printf("thread %ld is working, number = %d ,g_value = %d\n",
        pthread_self(), num, g_value++);
    // sleep(1);
    // sleep(1);
}

int main()
{
    // 创建线程池
    ThreadPool* pool = threadPoolCreate(3, 10, 100);
    for (int i = 0; i < 100000; ++i)
    {
        // int* num = (int*)malloc(sizeof(int));
        // *num = i + 100;
        threadPoolAdd(pool, taskFunc,  (void*)(intptr_t)(i + 100));
        // threadPoolAdd(pool, taskFunc,  (void*)(i + 100));
    }

    sleep(30);

    threadPoolDestroy(pool);
    return 0;
}
